package com.izobnehc.rabbit.rabbitframework.common.domain;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {

    private Integer code;

    private String message;

    private T data;

    private static final Integer SUCCESS_CODE = 200;

    private static final String SUCCESS_MESSAGE = "操作成功";

    private static final Integer ERROR_CODE = 500;

    private static final String ERROR_MESSAGE = "系统异常";

    public static <T> Result<T> success() {
        return new Result<T>(SUCCESS_CODE, SUCCESS_MESSAGE, null);
    }

    public static <T> Result<T> success(T data) {
        return new Result<T>(SUCCESS_CODE, SUCCESS_MESSAGE, data);
    }

    public static <T> Result<T> success(String message, T data) {
        return new Result<T>(SUCCESS_CODE, message, data);
    }

    public static <T> Result<T> fail(Integer code, String message, T data) {
        return new Result<T>(code, message, data);
    }

    public static Result<Boolean> fail(Integer code, String message) {
        return new Result<>(code, message, false);
    }

    public static <T> Result<T> error() {
        return new Result<T>(ERROR_CODE, ERROR_MESSAGE, null);
    }

    public static <T> Result<T> error(Integer code, String message, T data) {
        return new Result<T>(code, message, data);
    }

    public static Result<Boolean> error(Integer code, String message) {
        return new Result<>(code, message, false);
    }
}
